# https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/
# 718. 最长重复子数组
from typing import List


class Solution:
    def findLength(self, nums1: List[int], nums2: List[int]) -> int:
        n1 = len(nums1)
        n2 = len(nums2)
        result = -1
        dp = [[0 for i in range(n2 + 1)] for i in range(n1 + 1)]
        # print(dp)
        for i in range(1, n1 + 1):
            for j in range(1, n2 + 1):
                if nums1[i - 1] == nums2[j - 1]:
                    dp[i][j] = dp[i - 1][j - 1] + 1
                result = max(result, dp[i][j])
        # print(dp)
        return result


if __name__ == '__main__':
    a = Solution()
    print(a.findLength([1, 2, 3, 2, 1], [3, 2, 1, 4]))
